package com.yamaha.bikemarket;

import java.net.SocketTimeoutException;

import android.content.Context;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.yamaha.bikemarket.util.LogUtil;

public class MyAsyncHttpResponseHandler extends AsyncHttpResponseHandler {

	private final String name;
	private final Context context;

	public MyAsyncHttpResponseHandler(final String name, final Context context) {
		this.name = name;
		this.context = context;
	}

	@Override
	public void onStart() {
		super.onStart();

		LogUtil.i("Call WebService", "WebService : " + name + ", Started...");
	}

	@Override
	public void onSuccess(String res) {
		super.onSuccess(res);

		LogUtil.i("Call WebService", "WebService : " + name + ", Success...");
		LogUtil.i("Call WebService", "Response : " + res);
	}

	@Override
	public void onFailure(Throwable e, String error) {
		super.onFailure(e, error);

		LogUtil.e("Call WebService", "WebService : " + name + ", Failure", e);

		if (e instanceof SocketTimeoutException) {
			Toast.makeText(this.context, "No Connection, Please try again.",
					Toast.LENGTH_LONG).show();
		} else {
			Toast.makeText(this.context, error, Toast.LENGTH_LONG).show();
		}

	}

	@Override
	public void onFinish() {
		super.onFinish();

		LogUtil.i("Call WebService", "WebService : " + name + ", Finished.");
	}

}
